#!/usr/bin/env python
# Python Network Programming Cookbook -- Chapter -1
# THis program is optinmized for python 2.7. It may run on any
# other Python version with/without modifications.

import socket

def print_machine_info(host_name='localhost'):
    if not host_name:
        host_name = socket.gethostname()
    try:
        ip_address = socket.gethostbyname(host_name)
    except socket.error, err_msg:
        print "%s: %s" % (host_name, err_msg)
        return None
    print "Host name: %s" % host_name
    print "IP address: %s" % ip_address
    return (host_name, ip_address)

if __name__ == "__main__":
    print_machine_info()
